<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: admenvboxadd.php,v $ 
 * $Date: 2007/07/30 21:16:45 $ 
 * $Revision: 1.3 $ 
 * 
 * ********* CVS HEADER ********* 
 */
if (!isset($envid)) {
	rportalerreur("Aucun environnement en param&egrave;tre !","?op=admenvliste");
}
require_once(get_path_module("environnement.environnement"));
require_once(get_path("param")."environnement.php");
$query="SELECT * FROM environnement WHERE id='$envid'";
$result=rportalrequete($query) or rportalerreur($query,"?op=admenvliste");
if($environnement=rportalligne($result)){
	$L_base_env = get_env_path();
    $env=new environnement;
    $env=restaure_environnement($environnement['environnement']);
    if($action=="process"){
        $query="SELECT * FROM rportal_boxtype WHERE id='$boxtype'";
        $result=rportalrequete($query) or rportalerreur($query,"?op=admenvliste");
        if($boxtype=rportalligne($result)){}
        if($tplid>=0)   $tpl = $env->gettpl($tplid);
        if($argid>=0){
            $box=$env->getbox($argid);
            $box->setnom($nom);
            $box->setdescription($description);
            $box->setmode($mode);
            $box->setenvironnement($env->getnom());
            if($tplid>=0)   $box->settemplate($tpl->getfichier());
            $box->settype($boxtype['id']);
            $box->settypenom($boxtype['nom']);
            $box->settypedescription($boxtype['description']);
            $box->setrepertoire($boxtype['repertoire']);
            $env->setbox($argid,$box);
        }else{
            $box=new $boxtype['nom'];
            $param=new parametre;
            $box->setnom($nom);
            $box->setdescription($description);
            $box->setmode($mode);
            $box->setenvironnement($env->getnom());
            if($tplid>=0)   $box->settemplate($tpl->getfichier());
            $box->settype($boxtype['id']);
            $box->settypenom($boxtype['nom']);
            $box->settypedescription($boxtype['description']);
            $box->setrepertoire($boxtype['repertoire']);
            $box->setparam($param);
            $env->addbox($box);
        }
        $modif = $environnement['modification'];
        $modif = "Ajout du box ".$box->getnom().".\n" . $modif;
        $query="UPDATE environnement SET environnement='".$env->serialize()."',lastmod=NOW(),modification='".addslashes($modif)."' WHERE id='$envid'";
        @rportalrequete($query) or die ("ERREUR: $query<br />");	
        header("Location: ?op=admenvmod&argid=$envid");
        exit;
    }
    require_once(get_path("module")."TPLN/TPLN.php");
    $TPLN = new TPLN;
    $TPLN->Open($op_basepath.get_path("tpl")."admenvboxadd.html");
	$TPLN->IncludeFile("header",$L_base_env.$session['environnement']."/header.php");
	$TPLN->IncludeFile("footer",$L_base_env.$session['environnement']."/footer.php");
	
	require_once(get_path_module("admin")); 
	$pc = new panneau_controle(); 
	$pc->calculRubriqueParFonction('admenvliste'); 
	$TPLN->Parse("panneau_controle",$pc->retourneEntete());
	
    if(isset($argid)){
        $box=$env->getbox($argid);
        $TPLN->Parse("envid",$envid);
        $TPLN->Parse("boxid",$argid);
        $TPLN->Parse("nom",$box->getnom());
        $TPLN->Parse("description",$box->getdescription());
        if($box->getmode()==0){
            $TPLN->Parse("stat_check","checked");
            $TPLN->Parse("dyn_check",'');
        }else{
            $TPLN->Parse("stat_check",'');
            $TPLN->Parse("dyn_check","checked");
        }
        $TPLN->Parse("type_id",$box->gettype());
        $query="SELECT * FROM rportal_boxtype WHERE id='".$box->gettype()."'";
        $result=rportalrequete($query) or die ("ERREUR: $query<br />");
        if($type=rportalligne($result)){
            $TPLN->Parse("type_nom",$type[nom]);
            $TPLN->Parse("type_description",nl2br($type['description']));
        }
        if($env->getnbtpl()==0){
            $TPLN->EraseBloc("tpl");   
        }
        for($i=0;$i<$env->getnbtpl();$i++){
            $tpl = $env->gettpl($i);
            $TPLN->Parse("tpl.tpl_nom",$tpl->getnom());
            $TPLN->Parse("tpl.tpl_id",$tpl->getid());
            if($tpl->getfichier()==$box->gettemplate()){
                $TPLN->Parse("tpl.tpl_select","selected");
            } else {
                $TPLN->Parse("tpl.tpl_select","");
            }
            $TPLN->Loop("tpl");
        }
        $TPLN->Write();
        exit;
    }
}
$TPLN->Parse("envid",$envid);
$TPLN->Parse("boxid",'-1');
$TPLN->Parse("nom",'');
$TPLN->Parse("description",'');
$TPLN->Parse("stat_check","checked");
$TPLN->Parse("dyn_check",'');
$TPLN->Parse("type_id",$boxtype);
$query="SELECT * FROM rportal_boxtype WHERE id='$boxtype'";
$result=rportalrequete($query) or rportalerreur($query,"?op=admenvliste");
if($type=rportalligne($result)){
    $TPLN->Parse("type_nom",$type['nom']);
    $TPLN->Parse("type_description",nl2br($type['description']));
}
if($env->getnbtpl()==0){
            $TPLN->EraseBloc("tpl");   
}
for($i=0;$i<$env->getnbtpl();$i++){
    $tpl = $env->gettpl($i);
    $TPLN->Parse("tpl.tpl_nom",$tpl->getnom());
    $TPLN->Parse("tpl.tpl_id",$tpl->getid());
    if($tpl->getid()==$template){
        $TPLN->Parse("tpl.tpl_select","selected");
    }else{
        $TPLN->Parse("tpl.tpl_select",'');
    }
    $TPLN->Loop("tpl");
}
$TPLN->Write();
?>
